package model.monster
{
	import embeds.EmbedRes;
	
	import model.vo.monster.LMonsterAppearVo;
	import model.vo.monster.LMonsterAttackVo;
	import model.vo.monster.LMonsterCatchVo;
	import model.vo.monster.LMonsterCollectVo;
	import model.vo.monster.LMonsterDestroyVo;
	import model.vo.monster.LMonsterItemEffectVo;
	import model.vo.monster.LMonsterMeatQualityVo;
	import model.vo.monster.LMonsterSizeVo;
	import model.vo.monster.LMonsterSpEffectVo;
	import model.vo.monster.MonsterIntroVo;
	import model.vo.monster.MonsterListVo;
	import model.vo.monster.SMonsterVo;
	import model.vo.monster.SpVo;
	
	import org.robotlegs.mvcs.Actor;
	
	
	
	/**
	 * 怪物情报数据模型
	 * @author £iang
	 * 
	 */	
	public class MonsterModel extends Actor
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 当前操作的视频 */
		public var curDealingVideo:SpVo;
		/**  当前视频操作 “add” & “edit” */
		public var curVideoOperation:String;

		/** 大型-怪物介绍列表 */
		public var lIntroList:Vector.<MonsterIntroVo> = new Vector.<MonsterIntroVo>;
		/** 大型-鸟龙种怪物分类列表 */
		public var lBirdList:Vector.<MonsterListVo> = new Vector.<MonsterListVo>;
		/** 大型-飞龙种怪物分类列表 */
		public var lFlyList:Vector.<MonsterListVo> = new Vector.<MonsterListVo>;
		
		/** 当前阅读的怪物id */
		public var curReadMonsterId:int = 0;
		/** 当前大型怪物-肉质数据 */
		public var curLMonsterMeatData:Vector.<LMonsterMeatQualityVo> = new Vector.<LMonsterMeatQualityVo>;
		/** 当前大型怪物-特殊攻击效果数据 */
		public var curLMonsterSpData:Vector.<LMonsterSpEffectVo> = new Vector.<LMonsterSpEffectVo>;
		/** 当前大型怪物-道具效果数据 */
		public var curLMonsterItemData:Vector.<LMonsterItemEffectVo> = new Vector.<LMonsterItemEffectVo>;
		/** 当前大型怪物-剥取&掉落数据 */
		public var curLMonsterCollectData:Vector.<LMonsterCollectVo> = new Vector.<LMonsterCollectVo>;
		/** 当前大型怪物-破坏报酬数据 */
		public var curLMonsterDestroyData:Vector.<LMonsterDestroyVo> = new Vector.<LMonsterDestroyVo>;
		/** 当前大型怪物-捕获报酬数据 */
		public var curLMonsterCatchData:Vector.<LMonsterCatchVo> = new Vector.<LMonsterCatchVo>;
		/** 当前大型怪物-出现任务数据 */
		public var curLMonsterAppearData:Vector.<LMonsterAppearVo> = new Vector.<LMonsterAppearVo>;
		/** 当前大型怪物-体型数据 */
		public var curLMonsterSizeData:Vector.<LMonsterSizeVo> = new Vector.<LMonsterSizeVo>;
		/** 当前大型怪物-攻击方式数据 */
		public var curLMonsterAttackData:Vector.<LMonsterAttackVo> = new Vector.<LMonsterAttackVo>;
		/** 当前大型怪物-视频收藏数据 */
		public var curLMonsterVideoData:Vector.<SpVo> = new Vector.<SpVo>;
		
		/** 当前种类小型怪物数据 */
		public var curSMonsterTypeData:Vector.<SMonsterVo> = new Vector.<SMonsterVo>;
		/** 大型怪物狂化肉质数据 */
		public var lMonsterBerserkerMeatData:Array;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化数据 
		 * 
		 */		
		public function initData():void
		{
			var parseXML:XML;
			
			parseXML = XML( new EmbedRes.LMONSTER_INTRO() );
			
			for each ( var introObj:Object in parseXML.monster )
			{
				lIntroList.push( mapObj2MonsterIntroVo( introObj ) );
			}
			
			parseXML = XML( new EmbedRes.BIRD_LIST_XML() );
			
			for each ( var birdObj:Object in parseXML.bird )
			{
				lBirdList.push( mapObj2MonsterListVo( birdObj ) );
			}
			
			parseXML = XML( new EmbedRes.FLY_LIST_XML() );
			
			for each ( var flyObj:Object in parseXML.fly )
			{
				lFlyList.push( mapObj2MonsterListVo( flyObj ) );
			}
			
			parseXML = XML( new EmbedRes.LMONSTER_S_DATA() );
			
			lMonsterBerserkerMeatData = ( parseXML.berserker.toString() ).split( "," );
		}
		
		/**
		 * 获取当前查看大型怪物介绍 
		 * @return  大型怪物介绍 
		 * 
		 */		
		public function getCurLMonsterIntro():MonsterIntroVo
		{
			var resultIndex:int = 0;
			var len:int = lIntroList.length;
			
			for ( var i:int = 0; i < len; i ++ )
			{
				if ( ( lIntroList[ i ] as MonsterIntroVo ).monsterId == curReadMonsterId )
				{
					resultIndex = i;
					break;
				}
			}
			
			return lIntroList[ resultIndex ] as MonsterIntroVo;
		}
		
		/**
		 * 设置当前大型怪物肉质数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterMeatData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterMeatData )
				curLMonsterMeatData.length = 0;
			curLMonsterMeatData = new Vector.<LMonsterMeatQualityVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterMeatData.push( mapObj2LMonsterMeatQualityVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物特殊攻击效果数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterSpData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterSpData )
				curLMonsterSpData.length = 0;
			curLMonsterSpData = new Vector.<LMonsterSpEffectVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterSpData.push( mapObj2LMonsterSpEffectVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物道具效果数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterItemData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterItemData )
				curLMonsterItemData.length = 0;
			curLMonsterItemData = new Vector.<LMonsterItemEffectVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterItemData.push( mapObj2LMonsterItemEffectVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物剥取&掉落数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterCollectData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterCollectData )
				curLMonsterCollectData.length = 0;
			curLMonsterCollectData = new Vector.<LMonsterCollectVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterCollectData.push( mapObj2LMonsterCollectVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物破坏报酬数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterDestroyData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterDestroyData )
				curLMonsterDestroyData.length = 0;
			curLMonsterDestroyData = new Vector.<LMonsterDestroyVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterDestroyData.push( mapObj2LMonsterDestroyVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物捕获报酬数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterCatchData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterCatchData )
				curLMonsterCatchData.length = 0;
			curLMonsterCatchData = new Vector.<LMonsterCatchVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterCatchData.push( mapObj2LMonsterCatchVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物出现任务数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterAppearData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterAppearData )
				curLMonsterAppearData.length = 0;
			curLMonsterAppearData = new Vector.<LMonsterAppearVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterAppearData.push( mapObj2LMonsterAppearVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物体型数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterSizeData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterSizeData )
				curLMonsterSizeData.length = 0;
			curLMonsterSizeData = new Vector.<LMonsterSizeVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterSizeData.push( mapObj2LMonsterSizeVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物攻击方式数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterAttackData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterAttackData )
				curLMonsterAttackData.length = 0;
			curLMonsterAttackData = new Vector.<LMonsterAttackVo>();
			len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterAttackData.push( mapObj2LMonsterAttackVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 设置当前大型怪物视频收藏数据 
		 * @param monsterId 怪物id
		 * 
		 */		
		public function setCurLMonsterVideoData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curLMonsterVideoData )
				curLMonsterVideoData.length = 0;
			curLMonsterVideoData = new Vector.<SpVo>();
			
			if ( arr )
				len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curLMonsterVideoData.push( mapObj2SpVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 清除大型怪物数据 
		 * 
		 */		
		public function clearCurLMonsterData():void
		{
			if ( curLMonsterMeatData )
			{
				curLMonsterMeatData.length = 0;
				curLMonsterMeatData = null;
			}
		
			if ( curLMonsterSpData )
			{
				curLMonsterSpData.length = 0;
				curLMonsterSpData = null;
			}
			
			if ( curLMonsterItemData )
			{
				curLMonsterItemData.length = 0;
				curLMonsterItemData = null;
			}
	
			if ( curLMonsterCollectData )
			{
				curLMonsterCollectData.length = 0;
				curLMonsterCollectData = null;
			}
		
			if ( curLMonsterDestroyData )
			{
				curLMonsterDestroyData.length = 0;
				curLMonsterDestroyData = null;
			}
	
			if ( curLMonsterCatchData )
			{
				curLMonsterCatchData.length = 0;
				curLMonsterCatchData = null;
			}
	
			if ( curLMonsterAppearData )
			{
				curLMonsterAppearData.length = 0;
				curLMonsterAppearData = null;
			}
			
			if ( curLMonsterSizeData )
			{
				curLMonsterSizeData.length = 0;
				curLMonsterSizeData = null;
			}
		
			if ( curLMonsterAttackData )
			{
				curLMonsterAttackData.length = 0;
				curLMonsterAttackData = null;
			}
		
			if ( curLMonsterVideoData )
			{
				curLMonsterVideoData.length = 0;
				curLMonsterVideoData = null;
			}
		
		}
		
		/**
		 * 设置当前种类小型怪物数据 
		 * @param arr 数据
		 * 
		 */	
		public function setCurSMonsterTypeData( arr:Array ):void
		{
			var len:int = 0;
			
			if ( curSMonsterTypeData )
				curSMonsterTypeData.length = 0;
			curSMonsterTypeData = new Vector.<SMonsterVo>();
			
			if ( arr )
				len = arr.length;
			
			for ( var i:int = 0; i < len; i++ )
			{
				curSMonsterTypeData.push( mapObj2SMonsterVo( arr[ i ] ) );
			}
		}
		
		/**
		 * 清除小型怪物数据 
		 * 
		 */		
		public function clearCurSMonsterData():void
		{
			if ( curSMonsterTypeData )
			{
				curSMonsterTypeData.length = 0;
				curSMonsterTypeData = null;
			}
		}
		
		/**
		 * 将object类型转换为MonsterListVo类型 
		 * @param obj object类型
		 * @return  MonsterListVo类型 
		 * 
		 */		
		private function mapObj2MonsterListVo( obj:Object ):MonsterListVo
		{
			var result:MonsterListVo = new MonsterListVo();
			
			result.monsterId = obj.@id;
			result.chName = obj.@ch;
			result.jpName = obj.@jp;
			return result;
		}
		
		/**
		 * 将object类型转换为MonsterIntroVo类型 
		 * @param obj object类型
		 * @return  MonsterIntroVo类型 
		 * 
		 */	
		private function mapObj2MonsterIntroVo( obj:Object ):MonsterIntroVo
		{
			var result:MonsterIntroVo = new MonsterIntroVo();
			
			result.monsterId = obj.@id;
			result.ch = obj.@ch;
			result.jp = obj.@jp;
			result.intro = obj.@intro
			return result;
		}
		
		
		/**
		 *  将object类型转换为LMonsterMeatQualityVo类型 
		 * @param obj object类型
		 * @return LMonsterMeatQualityVo类型 
		 * 
		 */		
		private function mapObj2LMonsterMeatQualityVo( obj:Object ):LMonsterMeatQualityVo
		{
			var result:LMonsterMeatQualityVo = new LMonsterMeatQualityVo();
			
			result.monsterId = obj.id;
			result.part = obj.part;
			result.cut = obj.cut;
			result.beat = obj.beat;
			result.shot = obj.shot;
			result.fire = obj.fire;
			result.water = obj.water;
			result.thunder = obj.thunder;
			result.ice = obj.ice;
			result.dragon = obj.dragon;
			result.dizzy = obj.dizzy;
			result.fear = obj.fear;
			result.bug = obj.bug;
			result.type = obj.type;
			return result;
		}
		
		/**
		 *  将object类型转换为LMonsterSpEffectVo类型 
		 * @param obj object类型
		 * @return LMonsterSpEffectVo类型 
		 * 
		 */		
		private function mapObj2LMonsterSpEffectVo( obj:Object ):LMonsterSpEffectVo
		{
			var result:LMonsterSpEffectVo = new LMonsterSpEffectVo();
			
			result.monsterId = obj.id;
			result.attribute = obj.attribute;
			result.poison = obj.poison;
			result.palsy = obj.palsy;
			result.sleep = obj.sleep;
			result.dizzy = obj.dizzy;
			result.fatigue = obj.fatigue;
			return result;
		}
		
		/**
		 *  将object类型转换为LMonsterItemEffectVo类型 
		 * @param obj object类型
		 * @return LMonsterItemEffectVo类型 
		 * 
		 */		
		private function mapObj2LMonsterItemEffectVo( obj:Object ):LMonsterItemEffectVo
		{
			var result:LMonsterItemEffectVo = new LMonsterItemEffectVo();
			
			result.monsterId = obj.id;
			result.itemName = obj.itemName;
			result.itemEffect = obj.itemEffect;
			result.reference = obj.reference;
			return result;
		}
		
		/**
		 * 将object类型转换为LMonsterCollectVo类型  
		 * @param obj Object类型
		 * @return LMonsterCollectVo类型  
		 * 
		 */		
		private function mapObj2LMonsterCollectVo( obj:Object ):LMonsterCollectVo
		{
			var result:LMonsterCollectVo = new LMonsterCollectVo();
			
			result.monsterId = obj.id;
			result.part = obj.part;
			result.times = obj.times;
			result.low = obj.lowVec;
			result.high = obj.highVec;
			result.condition = obj.condition;
			result.lowRatio = ( obj.lowRatio as String ).split( "," );
			result.highRatio = ( obj.highRatio as String ).split( "," );
			return result;
		}
		
		/**
		 * 将object类型转换为LMonsterDestroyVo类型  
		 * @param obj Object类型
		 * @return LMonsterDestroyVo类型  
		 * 
		 */		
		private function mapObj2LMonsterDestroyVo( obj:Object ):LMonsterDestroyVo
		{
			var result:LMonsterDestroyVo = new LMonsterDestroyVo();
			
			result.monsterId = obj.id;
			result.part = obj.part;
			result.low = obj.lowVec;
			result.high = obj.highVec;
			result.condition = obj.condition;
			result.lowRatio = ( obj.lowRatio as String ).split( "," );
			result.highRatio = ( obj.highRatio as String ).split( "," );
			return result;
		}
		
		/**
		 * 将object类型转换为LMonsterCatchVo类型  
		 * @param obj Object类型
		 * @return LMonsterCatchVo类型  
		 * 
		 */		
		private function mapObj2LMonsterCatchVo( obj:Object ):LMonsterCatchVo
		{
			var result:LMonsterCatchVo = new LMonsterCatchVo();
			
			result.monsterId = obj.id;
			result.low = obj.lowVec;
			result.high = obj.highVec;
			result.condition = obj.condition;
			result.lowRatio = ( obj.lowRatio as String ).split( "," );
			result.highRatio = ( obj.highRatio as String ).split( "," );
			return result;
		}
		
		/**
		 * 将object类型转换为LMonsterAppearVo类型  
		 * @param obj Object类型
		 * @return LMonsterAppearVo类型  
		 * 
		 */		
		private function mapObj2LMonsterAppearVo( obj:Object ):LMonsterAppearVo
		{
			var result:LMonsterAppearVo = new LMonsterAppearVo();
			
			result.monsterId = obj.id;
			result.quest = obj.quest;
			result.distinction = obj.distinction;
			result.level = obj.level;
			result.hp = obj.hp;
			result.attack = obj.attack;
			result.defence = obj.defence;
			result.fear = obj.fear;
			result.ps = obj.ps;
			return result;
		}
		
		/**
		 * 将object类型转换为LMonsterSizeVo类型  
		 * @param obj Object类型
		 * @return LMonsterSizeVo类型  
		 * 
		 */		
		private function mapObj2LMonsterSizeVo( obj:Object ):LMonsterSizeVo
		{
			var result:LMonsterSizeVo = new LMonsterSizeVo();
			
			result.monsterId = obj.id;
			result.distinction = obj.distinction;
			result.range = obj.range;
			result.appear = obj.appear;
			return result;
		}
		
		/**
		 * 将object类型转换为LMonsterAttackVo类型  
		 * @param obj Object类型
		 * @return LMonsterAttackVo类型  
		 * 
		 */		
		private function mapObj2LMonsterAttackVo( obj:Object ):LMonsterAttackVo
		{
			var result:LMonsterAttackVo = new LMonsterAttackVo();
			
			result.monsterId = obj.id;
			result.attack = obj.attack;
			result.damage = obj.damage;
			result.power = obj.power;
			result.dizzy = obj.dizzy;
			result.ps = obj.ps;
			result.attribute = [];
			
			if ( obj.attribute != null && obj.attribute != "" )
			{
				result.attribute = ( obj.attribute as String ).split( "," );
			}
			
			return result;
		}
		
		/**
		 * 将object类型转换为SpVo类型  
		 * @param obj Object类型
		 * @return SpVo类型  
		 * 
		 */		
		private function mapObj2SpVo( obj:Object ):SpVo
		{
			var result:SpVo = new SpVo();
			
			result.spId = obj.spId;
			result.monsterId = obj.id;
			result.name = obj.name;
			result.url = obj.url;
			result.star = obj.star;
			return result;
		}
		
		/**
		 * 将object类型转换为SMonsterVo类型  
		 * @param obj Object类型
		 * @return SMonsterVo类型  
		 * 
		 */		
		private function mapObj2SMonsterVo( obj:Object ):SMonsterVo
		{
			var result:SMonsterVo = new SMonsterVo();
			
			result.monsterId = obj.id;
			result.name = obj.name;
			result.way = obj.way;
			result.times = obj.times;
			result.ps = obj.ps;
			result.low = obj.lowVec;
			result.high = obj.highVec;
			return result;
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function MonsterModel()
		{
			super();
		}
	}
}